/*
 * 入库记录综合查询
 * 参数   交易码：trancode=51112
 */

package org.ccams.tran;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.ccams.domain.TpInHead;
import org.ccams.util.ConvertUtil;
import org.ccams.util.PageParameter;

public class Tran51112 extends AbstractJsonTran{

	@SuppressWarnings("unchecked")
	@Override
	protected void buildJSONObject(Map model, JSONObject json,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		PageParameter page = new PageParameter();
		int limit = Integer.parseInt(request.getParameter("limit"));
		int start = Integer.parseInt(request.getParameter("start"));
		String condition = request.getParameter("condition");
		try{
			Date startDate = new SimpleDateFormat("y-M-d").parse(request.getParameter("startDate"));
			page.setStartDate(startDate);
		}catch(Exception e){}
		try{
			Date endDate = new SimpleDateFormat("y-M-d").parse(request.getParameter("endDate"));
			Calendar ca =Calendar.getInstance();
			ca.setTime(endDate);
			ca.add(Calendar.DATE, 1);
			ca.add(Calendar.MILLISECOND, -1);
			endDate = ca.getTime();
			page.setEndDate(endDate);
		}catch(Exception e){}
		try{
			Integer commitState = Integer.parseInt(request.getParameter("commitState"));
			page.setState(commitState);
		}catch(Exception e){}
		
		page.setLimit(limit);
		page.setStart(start);
		page.setCondition(condition);
		
		List<TpInHead> list = getCcamsService().getTpinheadDao().getTpInHeadByPage(page);		
		int count = getCcamsService().getTpinheadDao().getCountByPage(page);
		
		json.putAll(ConvertUtil.objectcollect2json(list, count));
		
	}

}
